home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / text / frect.h next >
Encoding:
C/C++ Source or Header  |  2009-02-06  |  7.3 KB  |  269 lines

  1. /****************************************************************************
  2. ** $Id: frect.h 13161 2009-02-07 00:36:14Z malex $
  3. **
  4. ** Definition of FRect class
  5. **
  6. ** Created : 931028
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the kernel module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef FRECT_H
  39. #define FRECT_H
  40.  
  41. //#ifndef QT_H
  42. #include "fsize.h"
  43. //#endif // QT_H
  44.  
  45. #if defined(topLeft)
  46. #error "Macro definition of topLeft conflicts with FRect"
  47. // don't just silently undo people's defines: #undef topLeft
  48. #endif
  49.  
  50. class FRect                    // rectangle class
  51. {
  52. public:
  53.     FRect()    { x1 = y1 = 0; x2 = y2 = -1; }
  54.     FRect( FPoint &topleft, FPoint &bottomright );
  55.     FRect( FPoint &topleft, FSize &size );
  56.     FRect( qreal left, qreal top, qreal width, qreal height );
  57.  
  58.     bool   isNull()    const;
  59.     bool   isEmpty()    const;
  60.     bool   isValid()    const;
  61.     FRect  normalize()    const;
  62.  
  63.     qreal       left()    const;
  64.     qreal       top()    const;
  65.     qreal       right()    const;
  66.     qreal       bottom()    const;
  67.  
  68.     qreal &rLeft();
  69.     qreal &rTop();
  70.     qreal &rRight();
  71.     qreal &rBottom();
  72.  
  73.     qreal       x()        const;
  74.     qreal       y()        const;
  75.     void   setLeft( qreal pos );
  76.     void   setTop( qreal pos );
  77.     void   setRight( qreal pos );
  78.     void   setBottom( qreal pos );
  79.     void   setX( qreal x );
  80.     void   setY( qreal y );
  81.  
  82.     void   setTopLeft( FPoint &p );
  83.     void   setBottomRight( FPoint &p );
  84.     void   setTopRight( FPoint &p );
  85.     void   setBottomLeft( FPoint &p );
  86.  
  87.     FPoint topLeft()     const;
  88.     FPoint bottomRight() const;
  89.     FPoint topRight()     const;
  90.     FPoint bottomLeft()     const;
  91.     FPoint center()     const;
  92.  
  93.     void   rect( qreal *x, qreal *y, qreal *w, qreal *h ) const;
  94.     void   coords( qreal *x1, qreal *y1, qreal *x2, qreal *y2 ) const;
  95.  
  96.     void   moveLeft( qreal pos );
  97.     void   moveTop( qreal pos );
  98.     void   moveRight( qreal pos );
  99.     void   moveBottom( qreal pos );
  100.     void   moveTopLeft( FPoint &p );
  101.     void   moveBottomRight( FPoint &p );
  102.     void   moveTopRight( FPoint &p );
  103.     void   moveBottomLeft( FPoint &p );
  104.     void   moveCenter( FPoint &p );
  105.     void   moveBy( qreal dx, qreal dy );
  106.  
  107.     void   setRect( qreal x, qreal y, qreal w, qreal h );
  108.     void   setCoords( qreal x1, qreal y1, qreal x2, qreal y2 );
  109.     void   addCoords( qreal x1, qreal y1, qreal x2, qreal y2 );
  110.  
  111.     FSize  size()    const;
  112.     qreal       width()    const;
  113.     qreal       height()    const;
  114.     void   setWidth( qreal w );
  115.     void   setHeight( qreal h );
  116.     void   setSize( const FSize &s );
  117.  
  118.     FRect  operator|(const FRect &r) const;
  119.     FRect  operator&(const FRect &r) const;
  120.     FRect&  operator|=(const FRect &r);
  121.     FRect&  operator&=(const FRect &r);
  122.  
  123.     bool   contains( FPoint &p, bool proper=FALSE ) const;
  124.     bool   contains( qreal x, qreal y ) const; // inline methods, _don't_ merge these
  125.     bool   contains( qreal x, qreal y, bool proper ) const;
  126.     bool   contains( const FRect &r, bool proper=FALSE ) const;
  127.     FRect  unite( const FRect &r ) const;
  128.     FRect  intersect( const FRect &r ) const;
  129.     bool   intersects( const FRect &r ) const;
  130.  
  131.     friend bool operator==( const FRect &, const FRect & );
  132.     friend bool operator!=( const FRect &, const FRect & );
  133.  
  134. private:
  135. #if defined(Q_WS_X11) || defined(Q_OS_TEMP)
  136.     friend void qt_setCoords( FRect *r, qreal xp1, qreal yp1, qreal xp2, qreal yp2 );
  137. #endif
  138.  
  139.     qreal x1;
  140.     qreal y1;
  141.     qreal x2;
  142.     qreal y2;
  143.  
  144. };
  145.  
  146. bool operator==( const FRect &, const FRect & );
  147. bool operator!=( const FRect &, const FRect & );
  148.  
  149.  
  150. /*****************************************************************************
  151.   FRect stream functions
  152.  *****************************************************************************/
  153. // #ifndef QT_NO_DATASTREAM
  154. // Q_EXPORT QDataStream &operator<<( QDataStream &, const FRect & );
  155. // Q_EXPORT QDataStream &operator>>( QDataStream &, FRect & );
  156. // #endif
  157.  
  158. /*****************************************************************************
  159.   FRect inline member functions
  160.  *****************************************************************************/
  161.  
  162. inline FRect::FRect( qreal left, qreal top, qreal width, qreal height )
  163. {
  164.     x1 = (qreal)left;
  165.     y1 = (qreal)top;
  166.     x2 = (qreal)(left+width-1);
  167.     y2 = (qreal)(top+height-1);
  168. }
  169.  
  170. inline bool FRect::isNull() const
  171. { return x2 == x1-1 && y2 == y1-1; }
  172.  
  173. inline bool FRect::isEmpty() const
  174. { return x1 > x2 || y1 > y2; }
  175.  
  176. inline bool FRect::isValid() const
  177. { return x1 <= x2 && y1 <= y2; }
  178.  
  179. inline qreal FRect::left() const
  180. { return x1; }
  181.  
  182. inline qreal FRect::top() const
  183. { return y1; }
  184.  
  185. inline qreal FRect::right() const
  186. { return x2; }
  187.  
  188. inline qreal FRect::bottom() const
  189. { return y2; }
  190.  
  191. inline qreal &FRect::rLeft()
  192. { return x1; }
  193.  
  194. inline qreal & FRect::rTop()
  195. { return y1; }
  196.  
  197. inline qreal & FRect::rRight()
  198. { return x2; }
  199.  
  200. inline qreal & FRect::rBottom()
  201. { return y2; }
  202.  
  203. inline qreal FRect::x() const
  204. { return x1; }
  205.  
  206. inline qreal FRect::y() const
  207. { return y1; }
  208.  
  209. inline void FRect::setLeft( qreal pos )
  210. { x1 = (qreal)pos; }
  211.  
  212. inline void FRect::setTop( qreal pos )
  213. { y1 = (qreal)pos; }
  214.  
  215. inline void FRect::setRight( qreal pos )
  216. { x2 = (qreal)pos; }
  217.  
  218. inline void FRect::setBottom( qreal pos )
  219. { y2 = (qreal)pos; }
  220.  
  221. inline void FRect::setX( qreal x )
  222. { x1 = (qreal)x; }
  223.  
  224. inline void FRect::setY( qreal y )
  225. { y1 = (qreal)y; }
  226.  
  227. inline FPoint FRect::topLeft() const
  228. { return FPoint(x1, y1); }
  229.  
  230. inline FPoint FRect::bottomRight() const
  231. { return FPoint(x2, y2); }
  232.  
  233. inline FPoint FRect::topRight() const
  234. { return FPoint(x2, y1); }
  235.  
  236. inline FPoint FRect::bottomLeft() const
  237. { return FPoint(x1, y2); }
  238.  
  239. inline FPoint FRect::center() const
  240. { return FPoint((x1+x2)/2, (y1+y2)/2); }
  241.  
  242. inline qreal FRect::width() const
  243. { return  x2 - x1 + 1; }
  244.  
  245. inline qreal FRect::height() const
  246. { return  y2 - y1 + 1; }
  247.  
  248. inline FSize FRect::size() const
  249. { return FSize(x2-x1+1, y2-y1+1); }
  250.  
  251. inline bool FRect::contains( qreal x, qreal y, bool proper ) const
  252. {
  253.     if ( proper )
  254.         return x > x1 && x < x2 &&
  255.                y > y1 && y < y2;
  256.     else
  257.         return x >= x1 && x <= x2 &&
  258.                y >= y1 && y <= y2;
  259. }
  260.  
  261. inline bool FRect::contains( qreal x, qreal y ) const
  262. {
  263.     return x >= x1 && x <= x2 &&
  264.        y >= y1 && y <= y2;
  265. }
  266. // #define Q_DEFINED_QRECT
  267. // #include "qwinexport.h"
  268.  #endif // QRECT_H
  269.